﻿using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace System {
    public class Windows {
        /// <summary>
        /// 获取操作系统版本
        /// </summary>
        /// <returns></returns>
        public static string GetOsVersion() {
            try {
                return Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName").ToString();
            } catch {
                return Environment.OSVersion.VersionString;
            }
        }
        ///// <summary>
        ///// 获取当前进程的CPU使用率
        ///// </summary>
        ///// <returns></returns>
        //public static float GetCpuUsageForProcess() {
        //    using var process = Process.GetCurrentProcess();
        //    var currentProcessName = process.ProcessName;
        //    using var cpuCounter = new PerformanceCounter("Process","% Processor Time",currentProcessName);
        //    cpuCounter.NextValue();
        //    return cpuCounter.NextValue();
        //}
        ///// <summary>
        ///// 获取进程的CPU使用率
        ///// </summary>
        ///// <param name="processName">进程名字</param>
        ///// <returns></returns>
        //public static float GetCpuUsageForProcess(string processName) {
        //    using var cpuCounter = new PerformanceCounter("Process","% Processor Time",processName);
        //    cpuCounter.NextValue();
        //    return cpuCounter.NextValue();
        //}
    }
}
